***********************************************************************************
** title: How to survey citizens’ compliance with COVID-19 public health measures**
** jounral: Journal of Experimental Political Science							 **
** authors:	Daoust et al. 													     **
** date:	June 2020															 **
** dataset: Vox Pop Lab 														 **					
***********************************************************************************

*Study 2

*Load dataset
use "study2.dta", clear

*Note: to run the following, you need those two packages: cibar and grc1leg. Use the ssc install [cibar] [grc1leg] to use them.

**************************************************************
** 					Generate variables						**
**************************************************************

*Treatment v/s control group
gen face_saving=0
replace face_saving=1 if treatment=="Preamble"

*Compliance 
gen grocery=0 if q472_1=="No"
replace grocery=0 if q475_1=="No"
replace grocery=1 if q472_1=="Yes"
replace grocery=1 if q475_1=="Yes"
replace grocery=1 if q472_1=="Unsure"
replace grocery=1 if q475_1=="Unsure"
replace grocery=1 if q472_1=="As seldom as possible"

gen see_someone=0 if q472_2=="No"
replace see_someone=0 if q475_2=="No"
replace see_someone=1 if q472_2=="Yes"
replace see_someone=1 if q475_2=="Yes"
replace see_someone=1 if q472_2=="Unsure"
replace see_someone=1 if q475_2=="Unsure"
replace see_someone=1 if q472_2=="As seldom as possible"

gen receive_someone=0 if q472_3=="No"
replace receive_someone=0 if q475_3=="No"
replace receive_someone=1 if q472_3=="Yes"
replace receive_someone=1 if q475_3=="Yes"
replace receive_someone=1 if q472_3=="Unsure"
replace receive_someone=1 if q475_3=="Unsure"
replace receive_someone=1 if q472_3=="As seldom as possible"

gen work_outside=0 if q472_4=="No"
replace work_outside=0 if q475_4=="No"
replace work_outside=1 if q472_4=="Yes"
replace work_outside=1 if q475_4=="Yes"
replace work_outside=1 if q472_4=="Unsure"
replace work_outside=1 if q475_4=="Unsure"
replace work_outside=1 if q472_4=="As seldom as possible"

gen public_transport=0 if q472_5=="No"
replace public_transport=0 if q475_5=="No"
replace public_transport=1 if q472_5=="Yes"
replace public_transport=1 if q475_5=="Yes"
replace public_transport=1 if q472_5=="Unsure"
replace public_transport=1 if q475_5=="Unsure"
replace public_transport=1 if q472_5=="As seldom as possible"

gen hangout_other=0 if q472_6=="No"
replace hangout_other=0 if q475_6=="No"
replace hangout_other=1 if q472_6=="Yes"
replace hangout_other=1 if q475_6=="Yes"
replace hangout_other=1 if q472_6=="Unsure"
replace hangout_other=1 if q475_6=="Unsure"
replace hangout_other=1 if q472_6=="As seldom as possible"

gen hangout_within=0 if q472_7=="No"
replace hangout_within=0 if q475_7=="No"
replace hangout_within=1 if q472_7=="Yes"
replace hangout_within=1 if q475_7=="Yes"
replace hangout_within=1 if q472_7=="Unsure"
replace hangout_within=1 if q475_7=="Unsure"
replace hangout_within=1 if q472_7=="As seldom as possible"

gen deliver_food=0 if q472_8=="No"
replace deliver_food=0 if q475_8=="No"
replace deliver_food=1 if q472_8=="Yes"
replace deliver_food=1 if q475_8=="Yes"
replace deliver_food=1 if q472_8=="Unsure"
replace deliver_food=1 if q475_8=="Unsure"
replace deliver_food=1 if q472_8=="As seldom as possible"

*Sociodemographics 
gen female=0
replace female=1 if sex_weight=="Women"

gen uni=0
replace uni=1 if education_weight=="University degree"

tabulate region, generate(region)

gen french=0
replace french=1 if mothertongue_weight=="French"

gen english=0
replace english=1 if mothertongue_weight=="English"

gen allo=0
replace allo=1 if mothertongue_weight=="Other"

gen fr_en_allo=1 if french==1
replace  fr_en_allo=2 if english==1
replace  fr_en_allo=3 if allo==1

gen older=0
replace older=1 if age_weight=="45-64" 
replace older=1 if age_weight=="65+" 

*Other variables
gen ideology=self_placement
replace ideology=ideology/10

gen language_used=0 if userlanguage=="EN"
replace language_used=1 if userlanguage=="FR"
**************************************************************
** 							Labels							**
**************************************************************
label variable female "Women"
label variable uni "University"
label variable region1 "Alberta"
label variable region2 "Atlantic"
label variable region3 "British Columbia"
label variable region4 "Manitoba/Saskatchewan"
label variable region5 "Ontario"
label variable region6 "Québec"

**************************************************************
** 				 			Figure 1						**
**************************************************************
*First, we generate the graph. Second, we save them individually. 
cibar see_someone [aweight=weight], over1(face_saving)  level(84) ///
		graphopts(ylabel(0(.05).3) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("Mean of compliance")  title("Visit someone else's home", size(small)) ) 
graph save see_someone_study2.gph, replace

cibar receive_someone [aweight=weight], over1(face_saving)  ///
		graphopts(ylabel(0(.05).3) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("") title("Have someone over" "who does not live with you", size(small)) ) 
graph save receive_someone_study2.gph, replace	
		
cibar hangout_other [aweight=weight], over1(face_saving)  ///
		graphopts(ylabel(0(.05).3) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("") title("Get together outdoors" "with people who do not live with you", size(small)) ) 
graph save hangout_other_study2.gph, replace	

*Third, we merge them all three into one figure. Fourth, we save it. 
grc1leg  see_someone_study2.gph receive_someone_study2.gph hangout_other_study2.gph,  legendfrom(see_someone_study2.gph) ///
	row(1)  xsize(27) ysize(12) title("Study 2")
graph save figure1_study2.gph, replace

**************************************************************
** 				 		Table SM1							**
**************************************************************
est clear 
eststo: quietly estpost sum older female uni english french allo region* [aweight=weight] 		
esttab  using "Descriptives.rtf", cells("min mean(fmt(3)) sd(fmt(3)) max count")  label   mlabels(,titles) replace

**************************************************************
** 				 		Table SM2							**
**************************************************************
ttest older , by(face_saving) 
ttest female, by(face_saving)
ttest uni, by(face_saving)
ttest french, by(face_saving)
ttest english, by(face_saving)
ttest allo, by(face_saving)
ttest region1, by(face_saving) // As can be seen in the "Label" subsection above, region1 is Alberta
ttest region2, by(face_saving) // region2 is Atlantic
ttest region3, by(face_saving) // region3 is British Columbia
ttest region4, by(face_saving) // region4 is Manitoba/Saskatchewan (Prairies)
ttest region5, by(face_saving) // region5 is Ontario
ttest region6, by(face_saving) // region6 is Québec
ttest ideology, by(face_saving)

**************************************************************
** 				    	Figure SM1							**
**************************************************************

*This is for study 3 only: see the "study3.do" document.

**************************************************************
** 				   		Figure SM2							**
**************************************************************
*First, we run the logistic regressions. Second, we compute the marginal effect for "face_saving". 
*Third, we plot the effects. Fourth, we save each individual graph. 

eststo m1: logit see_someone face_saving ///
			older female uni english french allo region1 region2 region3 region4 region5 region6 ideology
margins, at(face_saving=(0 1))
marginsplot, level(84) ytitle("Predicted probability") title("Visit someone else’s home")  ///
						plotopts(connect(none)) ylabel(0(.05).25) xtitle("") xlabel(-1 " " 2 " " 0 "Control" 1 `" "Face-saving"  "treatment" "', labsize(vsmall))  
graph save  see_someone_sm2_study2.gph, replace

eststo m2:  logit receive_someone face_saving ///
			older female uni english french allo region1 region2 region3 region4 region5 region6 ideology
margins, at(face_saving=(0 1))
marginsplot, level(84) ytitle("") title("Have someone over at your home" "who does not live with you")  ///
						plotopts(connect(none)) ylabel(0(.05).25) xtitle("") xlabel(-1 " " 2 " " 0 "Control" 1 `" "Face-saving"  "treatment" "', labsize(vsmall))  
graph save  receive_someone_sm2_study2.gph, replace

eststo m3: logit hangout_other face_saving ///
			older female uni english french allo region1 region2 region3 region4 region5 region6 ideology
margins, at(face_saving=(0 1)) 
marginsplot, level(84) ytitle("") title("Get together outdoors with people" "who do not live with you ")  ///
						plotopts(connect(none)) ylabel(0(.05).25) xtitle("") xlabel(-1 " " 2 " " 0 "Control" 1 `" "Face-saving"  "treatment" "', labsize(vsmall))  
graph save  hangout_other_sm2_study2.gph, replace

*Fifth, we combine everything. Sixth, we save it. 
graph combine see_someone_sm2_study2.gph receive_someone_sm2_study2.gph hangout_other_sm2_study2.gph, row(1) xsize(9) title("Study 2")
graph save SM2_study2.gph, replace

**************************************************************
** 				 	Table SM3								**
*************************************************************
esttab m1 m2 m3 using "tableSM3.rtf", label mlabels(,titles) nogap nolines pr2  b(2) se(2)replace nostar

**************************************************************
** 				 	Figure SM3 & 6							**
**************************************************************

*See the .do for Study 1 and 3

**************************************************************
** 				 		 Figure SM4							**
**************************************************************
*First, we run the logistic regressions. Second, we compute the marginal effect for "face_saving" using dydx across each group of interest (male/female; no university/university/; each 0-10 ideology scale value). 
*Third, we plot the effects. Fourth, we save each individual graph. 
*Fifth, we combine everything. Sixth, we save it. 
*We repeat this for all three variables (female, university, ideology)

*Female
logit see_someone i.face_saving##i.female
margins, dydx(face_saving) at(female=(0 1)) post
marginsplot, level(84) yline(0)  ylabel(-.1(.05).2) title("Visit someone else's home", size(small)) ///
				ytitle("Predicted probability") plotopts(connect(none)) xlabel(-1 " " 2 " " 0 "Men" 1 "Women", labsize(vsmall)) xtitle("Sex")
graph save female1_study2.gph, replace

logit receive_someone i.face_saving##i.female
margins, dydx(face_saving) at(female=(0 1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Have someone over" "who does not live with you", size(small)) ///
				ytitle("") plotopts(connect(none)) xlabel(-1 " " 2 " " 0 "Men" 1 "Women", labsize(vsmall)) xtitle("Sex")
graph save female2_study2.gph, replace

logit hangout_other  i.face_saving##i.female
margins, dydx(face_saving) at(female=(0 1)) post
marginsplot, level(84)  yline(0) ylabel(-.1(.05).2) title("Get together outdoors" "with people who do not live with you", size(small)) ///
				ytitle("") plotopts(connect(none)) xlabel(-1 " " 2 " " 0 "Men" 1 "Women", labsize(vsmall)) xtitle("Sex")
graph save female3_study2.gph, replace

graph combine female1_study2.gph female2_study2.gph female3_study2.gph, row(1) xsize(9)
graph save female_sm3_study2.gph, replace

*University
logit see_someone  i.face_saving##i.uni
margins, dydx(face_saving) at(uni=(0 1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Visit someone else's home", size(small)) ///
				ytitle("Predicted probability") plotopts(connect(none)) xlabel(-1 " " 2 " " 0 `" "No uni"  "degree" "' 1 "Uni degree", labsize(vsmall)) xtitle("Education")
graph save uni1_study2.gph, replace

logit receive_someone i.face_saving##i.uni
margins, dydx(face_saving) at(uni=(0 1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Have someone over" "who does not live with you", size(small)) ///
				ytitle("") plotopts(connect(none)) xlabel(-1 " " 2 " " 0 `" "No uni"  "degree" "' 1 "Uni degree", labsize(vsmall)) xtitle("Education")
graph save uni2_study2.gph, replace

logit hangout_other  i.face_saving##i.uni
margins, dydx(face_saving) at(uni=(0 1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Get together outdoors" "with people who do not live with you", size(small)) ///
				ytitle("") plotopts(connect(none)) xlabel(-1 " " 2 " " 0 `" "No uni"  "degree" "' 1 "Uni degree", labsize(vsmall)) xtitle("Education")
graph save uni3_study2.gph, replace

graph combine uni1_study2.gph uni2_study2.gph uni3_study2.gph, row(1) xsize(9)
graph save uni_sm3_study2.gph, replace

*Ideology
logit see_someone i.face_saving##c.ideology
margins, dydx(face_saving) at(ideology=(0(.1)1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Visit someone else's home", size(small))  ///
				ytitle("Predicted probability")   xtitle("Left-right ideology")
graph save ideology1_study2.gph, replace

logit receive_someone i.face_saving##c.ideology
margins, dydx(face_saving) at(ideology=(0(.1)1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Have someone over" "who does not live with you", size(small)) ///
					ytitle("")   xtitle("Left-right ideology")
graph save ideology2_study2.gph, replace

logit hangout_other i.face_saving##c.ideology
margins, dydx(face_saving) at(ideology=(0(.1)1)) post
marginsplot, level(84)  yline(0) ylabel(-.1(.05).2) title("Get together outdoors" "with people who do not live with you", size(small)) ///
				ytitle("")   xtitle("Left-right ideology")
graph save ideology3_study2.gph, replace

graph combine ideology1_study2.gph ideology2_study2.gph ideology3_study2.gph, row(1) xsize(9) 
graph save ideology_sm3_study2.gph, replace

*Seventh, we merge the three figures that combined three figures each.
graph combine  female_sm3_study2.gph uni_sm3_study2.gph ideology_sm3_study2.gph, col(1) ysize(9)

**************************************************************
** 			Figure SM6 - Replication without weight			**
**************************************************************
*First, we run the logistic regressions. Second, we compute the marginal effect for "face_saving". 
*Third, we plot the effects. Fourth, we save each individual graph. 

cibar see_someone , over1(face_saving)  level(84) ///
		graphopts( ylabel(0(.05).3) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("Mean of compliance")  title("Visit someone else's home", size(small)) ) 
graph save see_someone.gph, replace

cibar receive_someone , over1(face_saving)  ///
		graphopts( ylabel(0(.05).3) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("") title("Have someone over" "who does not live with you", size(small)) ) 
graph save receive_someone.gph, replace	
		
cibar hangout_other , over1(face_saving)  ///
		graphopts( ylabel(0(.05).3) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("") title("Get together outdoors" "with people who do not live with you", size(small)) ) 
graph save hangout_other.gph, replace		
		
*Fifth, we combine everything. Sixth, we save it. 
grc1leg  see_someone.gph receive_someone.gph hangout_other.gph,  legendfrom(see_someone.gph) ///
	row(1)  xsize(27) ysize(12) title("Study 2") 
graph save noweight_study2.gph, replace

**************************************************************
** 				 	Figure SM7 - other items				**
**************************************************************
*First, we generate the graph. Second, we save them individually. 
cibar grocery [aweight=weight], over1(face_saving)  ///
		graphopts( ylabel(0(.1)1) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("") title("Go to the grocery store", size(small)) ) 
graph save grocery.gph, replace	


cibar work_outside [aweight=weight], over1(face_saving)  ///
		graphopts( ylabel(0(.1)1) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("") title("Go to work outside your home", size(small)) ) 
graph save work_outside.gph, replace	

cibar public_transport [aweight=weight], over1(face_saving)  ///
		graphopts( ylabel(0(.1)1) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("") title("Use public transportation", size(small)) ) 
graph save public_transport.gph, replace	

*Third, we merge them all three into one figure. Fourth, we save it. 
grc1leg   grocery.gph work_outside.gph public_transport.gph, legendfrom(grocery.gph)  row(1) xsize(9) title("Study 2")
graph save non_dangerous_items_study2.gph, replace
 
**************************************************************
** 			Figure SM8 - language of the questionnaire		**
**************************************************************
*First, we run the logistic regressions. Second, we compute the marginal effect for "face_saving" using dydx across each the values of "language_used". 
*Third, we plot the effects. Fourth, we save each individual graph. 
logit see_someone  i.face_saving##i.language_used
margins, dydx(face_saving) at(language_used=(0 1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Visit someone else's home", size(small)) ///
				ytitle("AME of face-saving treatment") plotopts(connect(none)) xlabel(-1 ""  0  "English"  1 "French" 2 "", labsize(vsmall)) xtitle("")
graph save languageused1_study2.gph, replace

logit receive_someone i.face_saving##i.language_used
margins, dydx(face_saving) at(language_used=(0 1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Have someone over" "who does not live with you", size(small)) ///
				ytitle("") plotopts(connect(none)) xlabel(-1 ""  0  "English"  1 "French" 2 "", labsize(vsmall)) xtitle("")
graph save languageused2_study2.gph, replace

logit hangout_other  i.face_saving##i.language_used
margins, dydx(face_saving) at(language_used=(0 1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Get together outdoors" "with people who do not live with you", size(small)) ///
				ytitle("") plotopts(connect(none)) xlabel(-1 ""  0  "English"  1 "French" 2 "", labsize(vsmall)) xtitle("")
graph save languageused3_study2.gph, replace

*Fifth, we combine everything. Sixth, we save it. 
graph combine languageused1_study2.gph languageused2_study2.gph languageused3_study2.gph, row(1) xsize(9) title("Study 2")
graph save languageused_study2.gph
